package dispatcher

import (
	"runtime/debug"

	"gitee.com/hasika/common-server/codec"
	"gitee.com/hasika/common-server/conn/inet"
)

type MultiDispatcher struct {
	all []MessageFunc
}

func NewMultiDispatcher(all ...MessageFunc) *MultiDispatcher {
	return &MultiDispatcher{all: all}
}

func (m *MultiDispatcher) DispatchMessage(data codec.Packet, conn inet.Conn) {
	defer func() {
		if err := recover(); err != nil {
			Log.Errorf("recover panic, packet %+v ,err %+v,stack %s", data, err, string(debug.Stack()))
		}
	}()
	for _, a := range m.all {
		a(data, conn)
	}
}
